﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh">
<head>
 <%@include file="../../commons/meta.jsp" %>
 <c:set var="baseUrl" value="${ctx}admin/adminauth/" scope="request"/>
 <c:set var="baseBusName" value="权限" scope="request"/>
</head>
<body>
<%@include file="../../commons/head.jsp" %>
<div class="content">
 <%@include file="../../commons/menu.jsp" %>
 <!--右侧展示部分-->
 <div class="right-zq">
  <!--center content-->
  <div class="dynamic">
   <form id="listForm" action="${baseUrl}" method="post">
    <!--新闻中心-->
    <div class="role dynamiclayer" style="display:block;">
     <div class="title orange2"><span class="left"><fmt:message key='User.permissions'/></span><label>
      > </label><span><fmt:message key='privilege'/></span></div>
     <div class="role-input role-input2">
      <ul class="input">
       <li class="p33">
        &nbsp;&nbsp;<fmt:message key='Access.code'/>：
        <input type="text" name="searchMap.authCode,like,string" class="input1 num" maxlength="20"/>
       </li>
       <li class="p33">
        &nbsp;&nbsp;<fmt:message key='Permission.to.name'/>：
        <input type="text" name="searchMap.authName,like,string" class="input1 num" maxlength="20"/>
       </li>
       <li class="p33">
        &nbsp;&nbsp;<fmt:message key='status'/> :
        <select name="searchMap.status,eq,int" class="input1 num" maxlength="20" style="text-align: center;">
         <option value="">- <fmt:message key='all'/> -</option>
         <option value="0"><fmt:message key='disable'/></option>
         <option value="1"><fmt:message key='available'/></option>
         <!-- <option value="-1">删除</option> -->
        </select>
       </li>
      </ul>
      <div class="button">
       <s:authorize access="hasAuthority('admin:auth:add')">
        <span class="orange2"><a href="${baseUrl}add"><fmt:message key='add'/></a></span>
       </s:authorize>
       <span class="orange2" onclick="listFormPageSearch(1)"><fmt:message key='query'/></span>
       <!--<span class="orange2 refresh" onclick="listFormPageSearch(1)">刷新</span>    -->
      </div>
     </div>
     <div class="role-table">
      <table cellspacing="0px" id="datatable">
      </table>
     </div>
     <div class="role-page">
      <input type="hidden" id="pageSize" name="pageSize" value="10"/>
      <ul id="datapagefoot">
      </ul>
     </div>
    </div>
   </form>
  </div>
  <!--center content over-->
 </div>
</div>
<script type="text/javascript">
 <s:authorize access="hasAuthority('admin:auth:remove')">
 function del(id) {
  var setIds = [];
  setIds.push(id);
//	 layer.confirm('确定要删除该条'+baseBusName+'数据？', {
  layer.confirm('<fmt:message key="sys.deleteSelectData"/>', {
   btn: ['<fmt:message key="determine"/>', '<fmt:message key="fanhou"/>']
   , btn2: function (index, layero) {
    layer.close(index);
   }, title: ['<fmt:message key='Delete.the.prompt'/>', true]
  }, function (index, layero) {
   rowDelete(setIds);
  });
 }
 </s:authorize>
 <s:authorize access="hasAuthority('admin:auth:remove')">
 function rowDelete(id) {
  debugs(id);
  $.ajax({
   url: "${baseUrl}remove",//?rand =+Math.random(),
   type: 'POST',
   contentType: "application/json",
   dataType: 'json',
   data: JSON.stringify({"ids": id}),
   success: function (data) {
    debugs(data);
    if (data != null && data.flag) {
     alertOk('<fmt:message key="sys.deleteSuccess"/>');
     $('#listForm').submit();
    } else {
     alertError('<fmt:message key="sys.deleteFailed"/>');
    }
   }
  });
 }
 </s:authorize>

 <s:authorize access="hasAuthority('admin:auth:edit')">
 function mod(roleCode) {
  window.location.href = "${baseUrl}edit/" + roleCode
 }
 </s:authorize>
 function rowGrant(roleCode) {
  if (empty(roleCode)) {
   alertError('<fmt:message key='Please.select'/>');
   return false;
  }
  debugs("rowGrant:${baseUrl}auth/" + roleCode);
  alert("${baseUrl}auth/" + roleCode);
  window.location.href = "${baseUrl}auth/" + roleCode
 }

 /**分页查询*/
 function listFormPageSearch(pageNum) {
  debugs("pageNum : " + pageNum);
  var pageForm = $("#listForm").serializeObject();
  debugs(pageForm);
  var pageCounts = $("#pageCounts").val();
  //debugs("pageForm.pageNumber:"+pageForm.pageNumber+isNumber(pageForm.pageNumber));
  checkPageNumber(pageForm, pageNum);

  pageForm.searchList = getSearchMapJson(pageForm);
  
  // 设置排序字段
  pageForm.sort = "authSeq";
  
  debugs("pageForm after");
  debugs(pageForm);
  var searchJsonUrl = '${baseUrl}page.json';
  var pageData = JSON.stringify(pageForm);
  debugs("ajax pageData 2: " + pageData);
  var tableHead = ['<fmt:message key='Access.code'/>', '<fmt:message key='Permission.to.name'/>', '<fmt:message key='status'/>', '<fmt:message key='parent.encoding'/>', '<fmt:message key='Serial.number'/>', '<fmt:message key='Creation.time'/>', '<fmt:message key='Update.time'/>', '<fmt:message key='operate'/>'];
  var tableHtml = getHead(tableHead);
  $.ajax({
   url: searchJsonUrl + "?rand=" + Math.random(),
   data: pageData,
   type: 'POST',
   contentType: "application/json",
   dataType: 'json',
   success: function (pages) {
    debugs("ajax return pages:");
    debugs(pages);
    //gridOptions.api.setRowData(pages.rows);
    var tr = "";
    $.each(pages.rows, function (index, item) {
     //debugs("ajax return pages pages.rows :");
     //debugs(item);
     // 将权限类型列屏蔽，authTypeValueGetter(item.authType), filtUndef(item.authUrl), 
     var trtmp = getValueTr([filtUndef(item.authCode), filtUndef(item.authName), getStatus(item.status),
      filtUndef(item.parentAuthCode), filtUndef(item.authSeq), getYmdTime(filtUndef(item.createdTime)),
      getYmdTime(filtUndef(item.updatedTime)),
      <s:authorize access="hasAuthority('admin:auth:edit')">
      '<a href="javascript:void(0);" onclick="mod(\'' + item.authCode + '\')"><fmt:message key="Modify.the"/></a>&nbsp;&nbsp;' +
      </s:authorize>
      <s:authorize access="hasAuthority('admin:auth:remove')">
      '<a href="javascript:void(0);" onclick="del(\'' + item.authCode + '\')"><fmt:message key="Deletes"/></a>' +
      </s:authorize>
      '']);
     tr += trtmp;
    });
    //debugs(tr);
    if (isEmpty(tr)) {
     tr = "<tr><td colspan='" + tableHead.length + "' class='error'><fmt:message key='Temporarily.no.data'/></td></tr>";
    }
    $("#datatable").html(tableHtml + tr);
    $("#pageSize").val(pages.pageSize);//","limit":5,"pageSize":5,"offset":0,"pageNumber" :1,
    $("#datapagefoot").html(getPageFoot(pages));
    debugs('$("#datapagefoot").html()');
    debugs($("#datapagefoot").html());
    //解决当上次查询无数据时，弹出 “请输入合理的页码范围!”提示
    if ($("#pageCounts").val() == "0") {
     $("#pageCounts").val("");
    }
   }, error: function (xhr) {
    alertError("<fmt:message key='The.error.message'/>: " + xhr.status + " " + xhr.statusText);//请求失败遇到异常触发
    $("#datapagefoot").html(getDefaultPageFoot());
   }
  });
 }
 listFormPageSearch(1);
</script>
<%@include file="../../commons/footpop.jsp" %>
</body>
</html>
